package HelperFinancial.DataBase;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ConfigurationHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME="configuracao.db";
	private static final int SCHEMA_VERSION=1;
	
	public ConfigurationHelper(Context context) {
		super(context, DATABASE_NAME, null, SCHEMA_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE config (_id INTEGER PRIMARY KEY AUTOINCREMENT, dateinit TEXT, dateend TEXT, category TEXT);");
	}
	
	public void insert(String dateInit, String dateEnd, String category) {
		ContentValues cv = new ContentValues();
		cv.put("dateinit", dateInit);
		cv.put("dateend", dateEnd);
		cv.put("category", category);
		getWritableDatabase().insert("config", "dateinit", cv);
	}
	
	public Cursor getAllConfiguration() {
		return(getReadableDatabase()
		.rawQuery("SELECT * FROM config",
		null));
	}
	
	public void removeAll() {
		getReadableDatabase().delete("config", null, null);
	}


	
	public void updateConfigurationDateInit(String data, String id){
		ContentValues cv = new ContentValues();
		cv.put("dateinit", data);
		getReadableDatabase().update("config", cv, "_id=" + id, null);
	}
	
	public void updateConfigurationDateEnd(String data, String id){
		ContentValues cv = new ContentValues();
		cv.put("dateend", data);
		getReadableDatabase().update("config", cv, "_id=" + id, null);
	}
	
	public void updateConfigurationCategory(String categoria, String id){
		ContentValues cv = new ContentValues();
		cv.put("category", categoria);	
		getReadableDatabase().update("config", cv, "_id=" + id, null);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}
	
}
